package main
import (
	"fmt"
	"sync"
)
var x2  = 0
func increment2(wg *sync.WaitGroup, ch chan bool) {
	ch <- true
	x2 = x2 + 1
	<- ch
	wg.Done()
}
func main() {
	var w2 sync.WaitGroup
	ch2 := make(chan bool, 1)
	for i := 0; i < 1000; i++ {
		w2.Add(1)
		go increment2(&w2, ch2)
	}
	w2.Wait()
	fmt.Println("final value of x", x2)
}